<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSpecificationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('specifications', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('规格表');
            $table->string('title')->nullable()->comment('规格名称标题');
            $table->string('name')->nullable()->comment('规格名称');
            $table->integer('sort')->default(0)->comment('排序');
        });

        Schema::create('category_specification', function (Blueprint $table) {
            $table->integer('specification_id')->comment('规格分类关联表');
            $table->integer('category_id');
            $table->index(['specification_id', 'category_id']);
        });

        Schema::create('specification_items', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('规格值表');
            $table->unsignedBigInteger('specification_id')->comment('规格ID');
            $table->string('item')->nullable()->comment('规格值名');
            $table->string('value')->nullable()->comment('规格值Value');
            $table->integer('sort')->default(0)->comment('排序');
        });

//        Schema::create('sku_specificationitem', function (Blueprint $table) {
//            $table->integer('sku_id')->comment('产品sku规格值关联表');
//            $table->integer('specification_item_id');
//            $table->index(['specification_item_id', 'sku_id']);
//            $table->timestamps();
//        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('specifications');
    }
}
